import React, { Component } from "react";
import "./index.css";
export default class Footer extends Component {
  handleClearDoneTodo = () => {
    this.props.clearDoneTodo();
  };
  handleChangeAllTodo = (event) => {
    const { changeAllTodo } = this.props;
    changeAllTodo(event.target.checked);
  };
  render() {
    const { todos } = this.props;
    const hasdone = todos.reduce((pre, todo) => {
      return todo.done ? (pre += 1) : pre;
    }, 0);
    const allTodos = todos.length;
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" onChange={this.handleChangeAllTodo} />
        </label>
        <span>
          <span>已完成{hasdone}</span>/ 全部{allTodos}
        </span>
        <button onClick={this.handleClearDoneTodo} className="btn btn-danger">
          清除已完成任务
        </button>
      </div>
    );
  }
}
